<?php 
require_once("abstractdatabase.php");
class piezometer extends MsssqlDB 
{
	private $sqlquery;
	
	public function __construct()
	 {
		 parent::__construct("mssql.infratechastm.com","infratechastm_dede","system1","infratechastm_Mockup");
	 }
	
	public function adddatapz($input)
	{
		
		$table ="id_pz,	
					model,		
					digit,		
					Serialno,	
					Linear,		
					capacity,	
					 mH,		
					Thermalfactor,
					Cablelength,	
					depth,		
					a,		
					b,		
					c,		
					location,
					pzi
					";
				
		$this->sqlquery = $this->insertdatasql($table,"piezometer",$input);
		$this->dbclose();
		return $this->sqlquery;
		
		
		}
		
		public function editdatapz($id_pz,$model,$digit,$Serialno,$Linear,$capacity,$mH,$Thermalfactor,$Cablelength,$depth,$a,$b,$c,$location)
		{
				
			$table ="model = $model,		
					 digit = $digit,		
					Serialno = $Serialno,	
					Linear = $Linear,		
					capacity = $capacity,	
					mH =$mH,		
					Thermalfactor = $Thermalfactor,
					Cablelength = $Cablelength,	
					depth = $depth,		
					a = $a,		
					b = $b,		
					c = $c,		
					location= $location";
					
					$this->sqlquery = $this->updatedatasql("piezometer",$table,"id_pz = $id_pz");					
					if(mysql_errno() > 0)  die (mysql_error());
					
			return $this->sqlquery;
			}
			
			
			public function deletepz($id_pz)
			{
				
				$id_pz1 = "id_pz='$id_pz'";
				$this->sqlquery = $this->deletesql("piezometer",$id_pz1);
				return $this->sqlquery;				
				
				}
	
	
			public function viewpz($id_localtion)
			{
			
				$table = "[dbo].[ProjectTools] 
						 INNER JOIN [dbo].[ToolType] ON [dbo].[ProjectTools].fkToolType = [dbo].[ToolType].pkToolType
						 INNER JOIN [dbo].[Project] ON [dbo].[ProjectTools].fkProject = [dbo].[Project].pkProject
						 INNER JOIN [dbo].[Piezometer] ON [dbo].[ProjectTools].fkTool = [dbo].[Piezometer].pkTool";
				
				
					
					if($id_localtion == '')
					{
						$condition = "[dbo].[ProjectTools].fkToolType = '1'";
					}else {
						$condition = "[dbo].[ProjectTools].fkToolType = '1' and [dbo].[ProjectTools].fkProject ='$id_localtion'";
					}
					

				return  $this->msssqlselectdata("*",$table,$condition);	;
			}
			
			
			public function viewclinometer($id_localtion)
			{
			
				$table = "[dbo].[ProjectTools] 
						 INNER JOIN [dbo].[ToolType] ON [dbo].[ProjectTools].fkToolType = [dbo].[ToolType].pkToolType
						 INNER JOIN [dbo].[Project] ON [dbo].[ProjectTools].fkProject = [dbo].[Project].pkProject
						 INNER JOIN [dbo].[Piezometer] ON [dbo].[ProjectTools].fkTool = [dbo].[Piezometer].pkTool";
				
				
					
					if($id_localtion == '')
					{
						$condition = "[dbo].[ProjectTools].fkToolType = '1'";
					}else {
						$condition = "[dbo].[ProjectTools].fkToolType = '1' and [dbo].[ProjectTools].fkProject ='$id_localtion'";
					}
					

				return  $this->msssqlselectdata("*",$table,$condition);	;
			}
			
			
			
			
			
			
			public function selectpzid($id_pz)
			{
				 $query = $this->selectdatasql("*","piezometer","id_pz = '$id_pz'");	 
				 return $this->mysqlfetcharray($query);
			}
			
			
			public function seletetable($id)
			{
				$query = $this->selectdatasql("*","localtionpz","id_local = '$id'");
				$tabledata = $this->mysqlfetcharray($query);
				return $tabledata['databasename'];
			}
			
			
			
			
		public function valuereport($pz)
		{
			
			$table ="A.id_pz,	
					model,		
					digit,		
					Serialno,	
					Linear,		
					capacity,	
					 mH,		
					Thermalfactor,
					Cablelength,	
					depth,		
					a,		
					b,		
					c,		
					location,
					pzi,
					B.name_local,project,
					";

			$this->sqlquery = $this->selectdatasql($table,"piezometer","A.location = B.id_local and id_pz = '$pz'");	
			
			return $this->mysqlfetcharray($this->sqlquery);
			
			}
			
			
			
			
			public function adddatapznumber($namedb,$date,$f,$t,$pointpz)
			{
				$fild = "pz0".$pointpz."a";
				$fild1 = "pz0".$pointpz."b";
				$add = $this->insertdatasql("measureddate,$fild,$fild1",$namedb,"$date,$f,$t");
				if(!$add)
				{
					
					}else{
						
				}

			}
			
			
			public function countnumberpz($id_pz)
			{
				$query = $this->selectdatasql("*","piezometer","location = '$id_pz'");
				return $this->mysqlnumrow($query);
				}
		
			 
			
	
	}

?>